
//
//  SelectedTypeView.m
//  PropertyMananger
//
//  Created by bh on 17/2/28.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "SelectedTypeView.h"
#import "SeletedTypeCell.h"

@interface SelectedTypeView() <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) NSArray * seletedTypeArr;
@property (nonatomic,strong) UITableView * tableView;

@end

@implementation SelectedTypeView
{
    UIWindow * window;
}

 static NSString * SelectedCellID = @"SelectedCellID";
- (instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSeletedTypeUI];
        
        self.isSelected = YES;
    }
    return self;
}
- (void)createSeletedTypeUI{

    self.seletedTypeArr = @[@"物业费",@"停车费"];

    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 60, BHscreenW, 100) style:UITableViewStylePlain];
    [self addSubview:self.tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.seletedTypeArr.count;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    SeletedTypeCell * cell = [SeletedTypeCell cellWithTableView:tableView];
    cell.titleLabel.text = self.seletedTypeArr[indexPath.row];
    
    return cell;

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 50;

}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 1;

}
- (void)selectedTypeView{

    window = [[UIWindow alloc] init];
    CGRect rect = [UIScreen mainScreen].bounds;
  //  CGRect rect = CGRectMake(0, 50, BHscreenW, BHscreenH - 50);
    [window makeKeyAndVisible];
    window.frame = rect;
    window.windowLevel = UIWindowLevelAlert;
    [window addSubview:self];
    window.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.5];
    UIView * bgView = [[UIView alloc] initWithFrame:rect];
    [window addSubview:bgView];
    [window bringSubviewToFront:self];
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [bgView addGestureRecognizer:tap];

}
- (void)tap:(UITapGestureRecognizer *)tap{
    
    [self dismissSelectedView];
    
}
- (void)dismissSelectedView
{
    [self removeFromSuperview];
    window.windowLevel = UIWindowLevelNormal;
    [window resignKeyWindow];
    window.backgroundColor = [UIColor clearColor];
    window = nil;
}

@end
